package com.okcl.manager.controller;

import com.okcl.manager.service.SysMenuService;
import com.okcl.model.entity.system.SysMenu;
import com.okcl.model.vo.common.Result;
import com.okcl.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "系统菜单接口")
@RequestMapping("/admin/system/sysMenu")
public class SysMenuController {
    @Resource
    private SysMenuService sysMenuService;

    /**
     * 菜单列表查询
     *
     * @return
     */
    @Operation(summary = "菜单列表查询")
    @GetMapping("/list")
    public Result queryMenuList() {
        sysMenuService.selectMenuList();
        return Result.build(sysMenuService.selectMenuList(), ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加菜单
     *
     * @param sysMenu
     * @return
     */
    @PostMapping("/add")
    public Result addMenu(@RequestBody SysMenu sysMenu) {
        sysMenuService.addMenu(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改菜单
     *
     * @param sysMenu
     * @return
     */
    @PutMapping("/edit")
    public Result editMenu(@RequestBody SysMenu sysMenu) {
        sysMenuService.editMenu(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 删除菜单
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteMenu(@PathVariable(value = "id") Long id) {
        sysMenuService.deleteMenu(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
}
